package example.step1;


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class TransientKeyword implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -8670388050122803308L;
    @Override
    public String toString() {
        return "TransientKeyword [name=" + name + ", age=" + age + "]";
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    private transient String name;
    private int age;
    // 运行函数
    public static void main(String args[]) throws Exception{
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\transient.obj"));
        // 序列化对象
        TransientKeyword person = new TransientKeyword();
        person.setAge(27);
        person.setName("Lang Yu");
        // 数据的序列化写入
        out.writeBoolean(true);
        out.writeObject(person);
        out.writeInt(120);
        out.writeObject("silentbalanceyh@126.com");
        out.close();
        // 反序列化对象
        ObjectInputStream in = new ObjectInputStream(new FileInputStream("E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\transient.obj"));
        // 数据的反序列化读取
        System.out.println(in.readBoolean());
        System.out.println(in.readObject());
        System.out.println(in.readInt());
        System.out.println(in.readObject());
        in.close();
    }
}